<?php
        $vod = true;
        $vid = $_GET['vid'];
        $stime = floor($_GET['s']/10)*10;
        $etime = ceil($_GET['e']/10)*10;
        if(!$stime){
                $now = time()-50;
                $stime = date('YmdHis',floor($now/10)*10);
                $etime = date('YmdHis',floor($now/10)*10+30);
                $vod = false;
        }
        $sequence=(strtotime($stime)-strtotime(20100101000000))/10;
        $sequence.="\n";
        $diff=(strtotime($etime)-strtotime($stime))/10;
        $videos = array();
        for($t=0;$t<$diff;$t++){
                $videos[]=date('YmdHis',strtotime($stime)+10*$t).".ts\n";
        }
        header("Content-Type: audio/mpegurl");
        $header="#EXTM3U\n#EXT-X-ALLOW-CACHE:NO\n#EXT-X-TARGETDURATION:10\n";
        $extinfo="#EXTINF:10,\n";
        $endlist="#EXT-X-ENDLIST\n";
        if($vod)
        {
                $result = $header;
                $result.="#EXT-X-MEDIA-SEQUENCE:$sequence";
                foreach($videos as $k=>$info){
                        $result.=$extinfo;
                        $result.="/timeshift/$vid/$info";
                }
                $result.=$endlist;
        }
        else
        {
                $result = $header;
                $result.="#EXT-X-MEDIA-SEQUENCE:$sequence";
                foreach($videos as $k=>$info){
                        $result.=$extinfo;
                        $result.="/timeshift/$vid/$info";
                }
        }
        echo $result;exit;